Count Within Month

Hi,
I'm trying to count all of the objects modified in a certain month. How would I go about doing this? I'm completely stuck on this problem...
Thanks!
josiah820 - Mon Jun 18 14:23:56 EDT 2012

Re: Count Within Month
Mathias Mamsch - Mon Jun 18 15:24:48 EDT 2012

Well the idea is to first get the start and the end of the month as a date. I like to use a trick for that (string / int conversion):
 

string pad2(int nr) { return (nr < 10) ? ("0" nr "") : (nr "") }
 
Date startOfMonth (Date d) {
   if (null d) return d
   int m = intOf stringOf (d, "MM") 
   int y = intOf stringOf (d, "yy")
 
   Date result = date("01/" (pad2 m) "/" (pad2 y), "dd/MM/yy") 
   return result
}
 
Date endOfMonth (Date d) {
   if (null d) return d
   int m = intOf stringOf (d, "MM") 
   int y = intOf stringOf (d, "yy")
 
   // increase the month 
   y = (m == 12) ? (y+1) : y
   m = (m == 12) ? 1 : (m+1)
 
   Date result = date("01/" (pad2 m) "/" (pad2 y), "dd/MM/yy") 
   return dateOnly dateOf ((intOf result) - 60*60*24)
}
 
Date d
 
d = date("15/02/2012", "dd/MM/yyyy") 
print "The start of February is: " (startOfMonth d) "\n"
print "The end of February is: " (endOfMonth d) "\n\n"
 
d = date("15/12/2012", "dd/MM/yyyy") 
print "The start of December is: " (startOfMonth d) "\n"
print "The end of December is: " (endOfMonth d) "\n\n"
 
d = date("15/01/2012", "dd/MM/yyyy") 
print "The start of January is: " (startOfMonth d) "\n"
print "The end of January is: " (endOfMonth d) "\n\n"

 


Once you have those dates it should be self explanatory. Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Count Within Month
llandale - Mon Jun 18 16:37:00 EDT 2012

I went about it differently:

const int       cl_SecsInDay    = 60*60*24
//*******************
int     fDateToDays(Date dateIn)
{     // Convert the date to the number of days since DOORS date origin started
        return(intOf(dateIn)/cl_SecsInDay)
}     // end fDateToDays()
 
//******************
Date    fDaysToDate(int Days)
{     // Convert the integer representing # Days to a date,
        //   Days must be positive or zero
        return(dateOf(Days*cl_SecsInDay))
}     // end fDaysToDate()
 
Date    fDaysAgo(int DaysAgo)
{     // Get the date it was that many DaysAgo
        int     DaysNow = fDateToDays(dateOnly(today()))
        return(dateOnly(fDaysToDate(DaysNow - DaysAgo)))
}
 
void    Test(int DaysAgo)
{
        print DaysAgo "\t" fDaysAgo(DaysAgo) "\n"
}
Test(1)
Test(30)


-Louie

Re: Count Within Month
Martin_Hunter - Tue Jun 19 06:02:39 EDT 2012

llandale - Mon Jun 18 16:37:00 EDT 2012

I went about it differently:

const int       cl_SecsInDay    = 60*60*24
//*******************
int     fDateToDays(Date dateIn)
{     // Convert the date to the number of days since DOORS date origin started
        return(intOf(dateIn)/cl_SecsInDay)
}     // end fDateToDays()
 
//******************
Date    fDaysToDate(int Days)
{     // Convert the integer representing # Days to a date,
        //   Days must be positive or zero
        return(dateOf(Days*cl_SecsInDay))
}     // end fDaysToDate()
 
Date    fDaysAgo(int DaysAgo)
{     // Get the date it was that many DaysAgo
        int     DaysNow = fDateToDays(dateOnly(today()))
        return(dateOnly(fDaysToDate(DaysNow - DaysAgo)))
}
 
void    Test(int DaysAgo)
{
        print DaysAgo "\t" fDaysAgo(DaysAgo) "\n"
}
Test(1)
Test(30)


-Louie

This maybe an even easier solution:-
 

string sMonth = "/04/2012"
 
Module m = current
Object o = current
Regexp rDate = regexp sMonth
int cnt = 0
History h
 
for o in entire m do {
   for h in o do {
      if (rDate stringOf (h.date))
      {
         cnt++
         break
      }
   }
}
 
print cnt " objects modified in month " sMonth

 

  • Martin

 

Re: Count Within Month
josiah820 - Tue Jun 19 08:13:24 EDT 2012

Martin_Hunter - Tue Jun 19 06:02:39 EDT 2012

This maybe an even easier solution:-
 

string sMonth = "/04/2012"
 
Module m = current
Object o = current
Regexp rDate = regexp sMonth
int cnt = 0
History h
 
for o in entire m do {
   for h in o do {
      if (rDate stringOf (h.date))
      {
         cnt++
         break
      }
   }
}
 
print cnt " objects modified in month " sMonth

 

  • Martin

 

What if I want to loop through all of the months, and export the number modified in EACH month between two specified dates? (like, If the user enters "January 1, 2010" and "December 31, 2010", how would I go about taking those values and exporting the number of operations per month within these two dates?
Thanks!